/********************************************************************************
Script name	: StarterKit.Schema
Description	: Create actual DB schema for database
********************************************************************************/
USE $(StarterKitDb)
GO

PRINT 'Droping constraints'
GO

DECLARE ConstraintsCursor CURSOR
FOR 
	SELECT o.[name], parent.name AS parentName
	FROM sysobjects o
		LEFT JOIN sysobjects parent ON o.parent_obj = parent.id
	WHERE o.xtype = 'F'
	ORDER BY o.[name]

DECLARE @tableName nvarchar(128),
	@constraintName nvarchar(128),
	@stmt nvarchar(4000)

OPEN ConstraintsCursor
FETCH NEXT FROM ConstraintsCursor INTO @constraintName, @tableName

WHILE @@FETCH_STATUS = 0
BEGIN
	PRINT 'Dropping constraint ''' + @constraintName + ''' on table ''' + @tableName + ''''
	SET @stmt = 
		'ALTER TABLE [' + @tableName COLLATE Latin1_General_CI_AS_KS + '] '+
		'DROP CONSTRAINT ['+ @constraintName COLLATE Latin1_General_CI_AS_KS+ ']'
	EXECUTE (@Stmt)
	FETCH NEXT FROM ConstraintsCursor INTO @constraintName, @tableName
END
GO

CLOSE ConstraintsCursor
DEALLOCATE ConstraintsCursor
GO

PRINT 'Creating schema'
GO

-----------------------------------------------------------------------------------
PRINT '-> dbo.SystemOption'
GO
IF OBJECT_ID('SystemOption') IS NULL
BEGIN
	CREATE TABLE dbo.SystemOption
	(
		OptionName       NVARCHAR(128) NOT NULL,
		OptionValue      NVARCHAR(128) NOT NULL,
		CONSTRAINT PK_SystemOption PRIMARY KEY CLUSTERED 
		(
			OptionName
		)
	)
END
GO

-----------------------------------------------------------------------------------
PRINT '-> dbo.Lookup'
GO
IF OBJECT_ID('Lookup') IS NULL
BEGIN
	CREATE TABLE dbo.[Lookup] 
	(
		LookupID 	INT NOT NULL,
		LookupName 	NVARCHAR (100) NOT NULL,
		IsEditable	BIT NOT NULL CONSTRAINT DF_Lookup_IsEditable DEFAULT(0),
		CONSTRAINT PK_Lookup PRIMARY KEY CLUSTERED 
		(
			LookupID
		),

		CONSTRAINT AK_Lookup UNIQUE NONCLUSTERED 
		(
			LookupName
		)	
	)
END
GO

-----------------------------------------------------------------------------------
PRINT '-> dbo.LookupCode'
GO
IF OBJECT_ID('LookupCode') IS NULL
BEGIN
	CREATE TABLE dbo.LookupCode
	(
		[CodeId]	UNIQUEIDENTIFIER NOT NULL ROWGUIDCOL,
		[LookupID]      INT NOT NULL,
		[IsActive]	BIT NOT NULL CONSTRAINT [DF_LookupCode_IsActive]  DEFAULT (1),
		CONSTRAINT PK_LookupCode PRIMARY KEY NONCLUSTERED 
		(
			CodeID
		)
	)
END
GO


PRINT '-> dbo.LookupValue'
GO

IF OBJECT_ID('LookupValue') IS NULL
BEGIN
	CREATE TABLE [dbo].[LookupValue]
	(
		[LookupValueId] [uniqueidentifier] NOT NULL ROWGUIDCOL,
		[LookupCodeId] [uniqueidentifier] NOT NULL,
		[CodeValue] [nvarchar](50) NOT NULL CONSTRAINT DF_LookupValue_CodeValue DEFAULT(''),
		[CodeName] [nvarchar](256) NOT NULL,
		[Culture] [nvarchar](50) NOT NULL,
		CONSTRAINT [PK_LookupValue] PRIMARY KEY NONCLUSTERED 
		(
			[LookupValueId]
		)
	)
END
GO

PRINT '-> dbo.MarketProperty'
GO
IF OBJECT_ID('MarketProperty') IS NULL
BEGIN
	CREATE TABLE dbo.[MarketProperty]
	(
		[MarketPropertyId] UNIQUEIDENTIFIER ROWGUIDCOL NOT NULL,
		[MarketId] UNIQUEIDENTIFIER NULL,
		[QuantityUnitId] UNIQUEIDENTIFIER NOT NULL,
		[PriceUnitId] UNIQUEIDENTIFIER NOT NULL,
		[IsSubUnit] BIT NOT NULL CONSTRAINT DF_MarketProperty_IsSubUnit DEFAULT(''),
		CONSTRAINT PK_MarketProperty PRIMARY KEY CLUSTERED 
		(
			[MarketPropertyId]
		)
	)
END
GO

PRINT '-> dbo.Currency'
GO
IF OBJECT_ID('Currency') IS NULL
BEGIN
	CREATE TABLE dbo.Currency
	(
		[CurrencyId]	UNIQUEIDENTIFIER NOT NULL ROWGUIDCOL,
		[Code] 		NVARCHAR (10) NOT NULL,
		[BasicUnit] 	NVARCHAR (50) NOT NULL CONSTRAINT DF_Currency_BasicUnit DEFAULT(''),
		[SubUnit] 	NVARCHAR (50) NOT NULL CONSTRAINT DF_Currency_SubUnit DEFAULT(''),
		CONSTRAINT PK_CurrencyId PRIMARY KEY NONCLUSTERED 
		(
			CurrencyId
		)
	)
END
GO

-----------------------------------------------------------------------------------
PRINT '-> dbo.StateCode'
GO
IF OBJECT_ID('StateCode') IS NULL
BEGIN
	CREATE TABLE dbo.[StateCode]
	(
		[Id] NVARCHAR (2) NOT NULL CONSTRAINT DF_StateCode_Id DEFAULT(''),
		[Name] 	NVARCHAR (256) NOT NULL,
		CONSTRAINT PK_StateCode PRIMARY KEY NONCLUSTERED 
		(
			[Id]
		)
	)
END
GO

PRINT '-> dbo.MarketEntity2UserInfo'
GO
IF OBJECT_ID('MarketEntity2UserInfo') IS NULL
BEGIN
	CREATE TABLE dbo.[MarketEntity2UserInfo]
	(
		[MarketEntity2UserInfoId] [uniqueidentifier] ROWGUIDCOL NOT NULL,
		[UserInfoId] [uniqueidentifier] NOT NULL,
		[MarketEntityId] [uniqueidentifier] NOT NULL,
		[LinkKind] INT NOT NULL CONSTRAINT [DF_MarketEntity2UserInfo_LinkKind] DEFAULT(0),
		CONSTRAINT PK_MarketEntity2UserInfo PRIMARY KEY CLUSTERED 
		(
			[MarketEntity2UserInfoId]
		)
	)

	CREATE INDEX IX_MarketEntity2UserInfo_UserInfoId ON dbo.[MarketEntity2UserInfo]
	(
		[UserInfoId]
	)		

	CREATE INDEX IX_MarketEntity2UserInfo_MarketEntityId ON dbo.[MarketEntity2UserInfo]
	(
		[MarketEntityId]
	)		
END
GO

PRINT '-> dbo.UserInfo'
GO
IF OBJECT_ID('UserInfo') IS NULL
BEGIN
	CREATE TABLE dbo.[UserInfo]
	(
		[UserInfoId] [uniqueidentifier] ROWGUIDCOL  NOT NULL CONSTRAINT [DF_UserInfo_UserInfoId] DEFAULT (newid()),
		[UserName] [nvarchar](100) NOT NULL CONSTRAINT [DF_UserInfo_UserName] DEFAULT(''),
		[Password] [varbinary](1024) NOT NULL,
		[FirstName] nvarchar(100) NULL, 
		[LastName] nvarchar(100) NULL, 
		[Role] [INT] NOT NULL CONSTRAINT DF_UserInfo_Role DEFAULT(0),
		[AddressId] [uniqueidentifier] NULL,
		[ContactInformationId] [uniqueidentifier] NULL,
		[IsActive] [bit] NOT NULL CONSTRAINT [DF_UserInfo_IsActive]  DEFAULT (1),
		[Commission] 	float NOT NULL,
		[BudgetVolume] 	float NOT NULL,
		[BudgetMonth] 	float NOT NULL,
		[Culture] nvarchar(50) NULL,
		[OfferColor] nvarchar(10) NULL,
		[OfferBackground] nvarchar(10) NULL,
		CONSTRAINT PK_UserInfo PRIMARY KEY CLUSTERED 
		(
			[UserInfoId]
		)
	)

	CREATE INDEX IX_UserInfo_UserName ON dbo.[UserInfo]
	(
		[UserName]
	)		
END
GO


PRINT '-> dbo.SitSecutity'
IF OBJECT_ID('SitSecutity') IS NULL
BEGIN
	CREATE TABLE dbo.[SitSecutity]
	(
		SitSecutityId [uniqueidentifier] ROWGUIDCOL NOT NULL, 
		UserInfoId    	[uniqueidentifier] NOT NULL,
		IP   		[NVARCHAR](15) NOT NULL,
		SecutityCode	[NVARCHAR](10) NULL,
		CONSTRAINT PK_SitSecutity PRIMARY KEY CLUSTERED
		(
			[SitSecutityId]
		)
	)
END
GO

PRINT '-> dbo.MarketIndex'
GO
IF OBJECT_ID('MarketIndex') IS NULL
BEGIN
	CREATE TABLE dbo.[MarketIndex]
	(
		[MarketIndexId] UNIQUEIDENTIFIER ROWGUIDCOL NOT NULL,
		[Name] NVARCHAR(100) NOT NULL,
		CONSTRAINT PK_MarketIndex PRIMARY KEY CLUSTERED 
		(
			[MarketIndexId]
		)
	)
END
GO

PRINT '-> dbo.MarketIndexRate'
GO
IF OBJECT_ID('MarketIndexRate') IS NULL
BEGIN
	CREATE TABLE dbo.[MarketIndexRate]
	(
		[MarketIndexRateId] UNIQUEIDENTIFIER ROWGUIDCOL NOT NULL,
		[MarketIndexId] UNIQUEIDENTIFIER NULL,
		[EffectiveDate] DATETIME NOT NULL,
		[Amount] MONEY NOT NULL,
		CONSTRAINT PK_MarketIndexRate PRIMARY KEY CLUSTERED 
		(
			[MarketIndexRateId]
		)
	)
END
GO

PRINT '-> dbo.PEXIndex'
GO
IF OBJECT_ID('PEXIndex') IS NULL
BEGIN
	CREATE TABLE dbo.[PEXIndex]
	(
		[PEXIndexId] UNIQUEIDENTIFIER ROWGUIDCOL NOT NULL,
		[MarketEntityId] UNIQUEIDENTIFIER NOT NULL,
		[IndexDate] DATETIME NOT NULL,
		[DayIndex] [MONEY] NOT NULL,
		[MonthIndex] [MONEY] NOT NULL,
		CONSTRAINT PK_PEXIndex PRIMARY KEY CLUSTERED
		(
			[PEXIndexId]
		)
	)
END
GO

PRINT '-> dbo.Settlement'
GO
IF OBJECT_ID('Settlement') IS NULL
BEGIN
	CREATE TABLE dbo.[Settlement]
	(
		[SettlementId] UNIQUEIDENTIFIER ROWGUIDCOL NOT NULL,
		[SettlementDate] DATETIME NOT NULL,
		[Comment] [NVARCHAR](2048) NULL,
		[Status] INT NOT NULL CONSTRAINT [DF_Settlement_Status] DEFAULT(0), --0-Draft 1-Published
		CONSTRAINT PK_Settlement PRIMARY KEY CLUSTERED 
		(
			[SettlementId]
		)
	)
END
GO

PRINT '-> dbo.SettlementContent'
GO
IF OBJECT_ID('SettlementContent') IS NULL
BEGIN
	CREATE TABLE dbo.[SettlementContent]
	(
		[SettlementContentId] UNIQUEIDENTIFIER ROWGUIDCOL NOT NULL,
		[SettlementId] UNIQUEIDENTIFIER NOT NULL,
		[PeriodType] INT NOT NULL CONSTRAINT [DF_SettlementContent_PeriodType] DEFAULT(0), -- 0-Month 1-Quarter
		[MarketTypeId] UNIQUEIDENTIFIER NOT NULL,
		[PeriodName] NVARCHAR(100) NOT NULL,
		[PeriodBegin] DATETIME NOT NULL,
		[PeriodEnd] DATETIME NOT NULL,
		[Amoint] MONEY NOT NULL CONSTRAINT [DF_SettlementContent_Amoint]  DEFAULT (0),
		CONSTRAINT PK_SettlementContent PRIMARY KEY CLUSTERED 
		(
			[SettlementContentId]
		)
	)
END
GO

PRINT '-> dbo.Address'
GO
IF OBJECT_ID('Address') IS NULL
BEGIN
	CREATE TABLE dbo.[Address]
	(
		[AddressId] [uniqueidentifier] ROWGUIDCOL NOT NULL CONSTRAINT [DF_Address_AddressId] DEFAULT(newid()),
		[Street] [nvarchar](200) NULL,
		[CountryId] [uniqueidentifier] NULL,
		[City] [nvarchar](100) NULL, 
		[State] [nvarchar](2) NULL,
		[Zip] [nvarchar](9) NULL,
		CONSTRAINT PK_Address PRIMARY KEY CLUSTERED 
		(
			[AddressId]
		)
	)
END
GO

PRINT '-> dbo.ContactInformation'
IF OBJECT_ID('ContactInformation') IS NULL
BEGIN
	CREATE TABLE dbo.[ContactInformation]
	(
		[ContactInformationId] [uniqueidentifier] ROWGUIDCOL NOT NULL 
			CONSTRAINT [DF_ContactInformation_ContactInformationId] DEFAULT(newid()),
		[Phone] [nvarchar](50) NULL,
		[Fax] [nvarchar](50) NULL,
		[Mobile] [nvarchar](50) NULL,
		[Other] [nvarchar](50) NULL,
		[Email] [nvarchar](50) NULL,
		CONSTRAINT PK_ContactInformation PRIMARY KEY CLUSTERED 
		(
			[ContactInformationId]
		)
	)
END
GO

PRINT '-> dbo.MarketState'
IF OBJECT_ID('MarketState') IS NULL
BEGIN
	CREATE TABLE dbo.[MarketState]
	(
		MarketStateId [uniqueidentifier] ROWGUIDCOL NOT NULL 
			CONSTRAINT [DF_MarketState_MarketStateId] DEFAULT(newid()),
		[State] [INT] NOT NULL CONSTRAINT [DF_MarketState_State] DEFAULT(1),
		/* Draft - 1 Online - 2 Offline - 3 */
		OnlineDate	[datetime] NULL,
		OnlineByUserId	[uniqueidentifier] NULL,
		OfflineDate	[datetime] NULL,
		OfflinebyUserId	[uniqueidentifier] NULL,
		
		CONSTRAINT PK_MarketState PRIMARY KEY CLUSTERED
		(
			[MarketStateId]
		)
	)
END
GO	


PRINT '-> dbo.Client'
IF OBJECT_ID('Client') IS NULL
BEGIN
	CREATE TABLE dbo.[Client]
	(
		ClientId [uniqueidentifier] ROWGUIDCOL NOT NULL 
			CONSTRAINT [DF_Client_ClientId] DEFAULT(newid()),
		[Name]       		NVARCHAR(255) NOT NULL,
		[ClientTypeId] 		[uniqueidentifier] NOT NULL,
		[ContactInformationId] 	[uniqueidentifier] NULL,
		[AddressId] 		[uniqueidentifier] NULL,
		[TaxTreatment]  	INT NOT NULL,
		[LimitAmount] 		float NOT NULL,
		[LimitMeasureId]	[uniqueidentifier] NULL,
		[Alias]			NVARCHAR(50) NULL CONSTRAINT [DF_Client_Alias] DEFAULT(''),
		[IsDefaultPreference]	bit NOT NULL CONSTRAINT [DF_Client_IsDefaultPreference] DEFAULT(1),
		[TaxId]			[uniqueidentifier] NULL
		CONSTRAINT PK_Client PRIMARY KEY CLUSTERED
		(
			[ClientId]
		)
	)
END
GO	

PRINT '-> dbo.Client2User'
IF OBJECT_ID('Client2User') IS NULL
BEGIN
	CREATE TABLE dbo.[Client2User]
	(
        	Client2UserId [uniqueidentifier] ROWGUIDCOL NOT NULL 
			CONSTRAINT [DF_Client2User_Client2UserId] DEFAULT(newid()),
		[UserInfoId]	[uniqueidentifier] NOT NULL,
		[ClientId]	[uniqueidentifier] NOT NULL,
		[UserRole]	INT NOT NULL,
		CONSTRAINT PK_Client2User PRIMARY KEY CLUSTERED
		(
			[Client2UserId]
		)
	)
END
GO	

PRINT '-> dbo.Client2Preference'
IF OBJECT_ID('Client2Preference') IS NULL
BEGIN
	CREATE TABLE dbo.[Client2Preference]
	(
        	Client2PreferenceId [uniqueidentifier] ROWGUIDCOL NOT NULL 
			CONSTRAINT [DF_Client2Preference_Client2PreferenceId] DEFAULT(newid()),
		ParentClientId 		[uniqueidentifier] NULL,
		ChildClientId 		[uniqueidentifier] NOT NULL,
		PreferenceId		[uniqueidentifier] NOT NULL,
		CONSTRAINT PK_Client2Preference PRIMARY KEY CLUSTERED
		(
			[Client2PreferenceId]
		)
	)
END
GO	

PRINT '-> dbo.Preference'
IF OBJECT_ID('Preference') IS NULL
BEGIN
	CREATE TABLE dbo.[Preference]
	(
    		PreferenceId [uniqueidentifier] ROWGUIDCOL NOT NULL 
			CONSTRAINT [DF_Preference_PreferenceId] DEFAULT(newid()),
		LC 			BIT NOT NULL,
		ClearingId 		[uniqueidentifier] NULL,
		OpenCredit 		[float] NOT NULL,
		NetOutExposure	BIT NOT NULL,
		ExposureId 		[uniqueidentifier] NULL,
		TermsConditionsId 	[uniqueidentifier] NULL,
		CurrencyId		[uniqueidentifier] NULL,
		LawId 			[uniqueidentifier] NULL,
		ArbitrationId		[uniqueidentifier] NULL,
		TradeRestriction 	BIT NOT NULL 
			CONSTRAINT [DF_Preference_TradeRestriction] DEFAULT(0),
		CONSTRAINT PK_Preference PRIMARY KEY CLUSTERED
		(
			[PreferenceId]
		)
	)
END
GO	

PRINT '-> dbo.Broker2Client'
IF OBJECT_ID('Broker2Client') IS NULL
BEGIN
	CREATE TABLE dbo.[Broker2Client]
	(
		Broker2ClientId [uniqueidentifier] ROWGUIDCOL NOT NULL 
			CONSTRAINT [DF_Broker2Client_Broker2ClientId] DEFAULT(newid()),
		UserInfoId	[uniqueidentifier] NOT NULL,  
		ClientId	[uniqueidentifier] NOT NULL,
		CONSTRAINT PK_Broker2Client PRIMARY KEY CLUSTERED
		(
			[Broker2ClientId]
		)
	)
END
GO	

PRINT '-> dbo.MarketEntity'
IF OBJECT_ID('MarketEntity') IS NULL
BEGIN
	CREATE TABLE dbo.[MarketEntity]
	(
		MarketEntityId	[uniqueidentifier] ROWGUIDCOL NOT NULL 
			CONSTRAINT [DF_MarketEntity_MarketEntityId] DEFAULT(newid()),
		MarketId	[uniqueidentifier] NOT NULL,
		MarketGroupId   [uniqueidentifier] NOT NULL,
		MarketTypeId    [uniqueidentifier] NOT NULL,
		TradePeriodBeginId [uniqueidentifier] NOT NULL,
		TradePeriodEndId   [uniqueidentifier] NOT NULL,
		IndexId   	[uniqueidentifier] NOT NULL,
		IndexPrice	float NOT NULL CONSTRAINT [DF_MarketEntity_IndexPrice] DEFAULT(18), /*Order in blotter*/
		CONSTRAINT PK_MarketEntity PRIMARY KEY CLUSTERED
		(
			[MarketEntityId]
		)
	)
END
GO

PRINT '-> dbo.MarketEntityLink'
IF OBJECT_ID('MarketEntityLink') IS NULL
BEGIN
	CREATE TABLE dbo.[MarketEntityLink]
	(
		MarketEntityLinkId [uniqueidentifier] ROWGUIDCOL NOT NULL 
			CONSTRAINT [DF_MarketEntityLink_MarketEntityLinkId] DEFAULT(newid()),
		MarketTypeId    [uniqueidentifier] NOT NULL,
		MarketGroupId   [uniqueidentifier] NOT NULL,
		MarketId	[uniqueidentifier] NOT NULL,
		CONSTRAINT PK_MarketEntityLink PRIMARY KEY CLUSTERED
		(
			[MarketEntityLinkId]
		)
	)
END
GO

PRINT '-> dbo.Order'
IF OBJECT_ID('Order') IS NULL
BEGIN
	CREATE TABLE dbo.[Order]
	(
		OrderId	[uniqueidentifier] ROWGUIDCOL NOT NULL 
			CONSTRAINT [DF_Order_OrderId] DEFAULT(newid()),
		OrderDate	[DateTime] NOT NULL, 
		MarketEntityId	[uniqueidentifier] NOT NULL,
		TraderId	[uniqueidentifier] NOT NULL,  
		ClientId	[uniqueidentifier] NOT NULL,
		Status	 	[INT] NOT NULL CONSTRAINT [DF_Order_Status] DEFAULT(0),
				/*0 - Active 1- Pending 2- Completed*/
		Operation	INT NOT NULL, /*ASK BID*/
				/*Order in blotter*/
		OperationPos    INT NOT NULL CONSTRAINT [DF_Order_OperationPos] DEFAULT(99), 
		Spread		float NOT NULL CONSTRAINT [DF_Order_Spread] DEFAULT(0),
		OrderPrice	float NOT NULL,
		OrderVolume     float NOT NULL, 
		LocationId	[uniqueidentifier] NULL,
		DeliveryId	[uniqueidentifier] NULL,  
		[Comment]	[NVARCHAR](2048) NULL,
		[BrokerId]	[uniqueidentifier] NOT NULL,  
		[MarketStateId] [uniqueidentifier] NULL,
		[EnteredPrice]	float NOT NULL CONSTRAINT [DF_Order_EnteredPrice] DEFAULT(0),
		OtherInfo 	[NVARCHAR](2048) NULL,
		Incoterms2010Id	[uniqueidentifier] NULL,
		DemurrageId 	[uniqueidentifier] NULL,
		InspectionSplitId [uniqueidentifier] NULL,
		CONSTRAINT PK_Order PRIMARY KEY CLUSTERED
		(
			[OrderId]
		)
	)
END
GO

PRINT '-> dbo.TradeActivity'
IF OBJECT_ID('TradeActivity') IS NULL
BEGIN
	CREATE TABLE dbo.[TradeActivity]
	(
		TradeActivityId	[uniqueidentifier] ROWGUIDCOL NOT NULL 
			CONSTRAINT [DF_TradeActivity_TradeActivityId] DEFAULT(newid()),
		TradeId		INT IDENTITY(1,1) NOT NULL,
		MarketEntityId	[uniqueidentifier] NOT NULL,
		ActivityDate	[DATETIME] NOT NULL,
		Status          [INT] NOT NULL CONSTRAINT [DF_TradeActivity_StatusId] DEFAULT(0),
		SellerOrderId	[uniqueidentifier] NOT NULL,
		BuyerOrderId	[uniqueidentifier] NOT NULL,  
		BrockerId	[uniqueidentifier] NOT NULL,
		Price		float NOT NULL,
		Volume     	float NOT NULL, 
		LocationId	[uniqueidentifier] NULL,
		DeliveryId	[uniqueidentifier] NULL,  
		MarketStateId	[uniqueidentifier] NULL,
		CONSTRAINT PK_OrderActivity PRIMARY KEY CLUSTERED
		(
			[TradeActivityId]
		)
	)
END
GO

PRINT '-> dbo.TradeActivityComment'
IF OBJECT_ID('TradeActivityComment') IS NULL
BEGIN
	CREATE TABLE dbo.[TradeActivityComment]
	(
		TradeActivityCommentId	[uniqueidentifier] ROWGUIDCOL NOT NULL 
			CONSTRAINT [DF_TradeActivityComment_TradeActivityCommentId] DEFAULT(newid()),
		TradeActivityId	[uniqueidentifier] NOT NULL,
		UserInfoId	[uniqueidentifier] NOT NULL,
		CommentDate	[DATETIME] NOT NULL,
		Content         [NVARCHAR](1024) NULL,
		CONSTRAINT PK_TradeActivityComment PRIMARY KEY CLUSTERED
		(
			[TradeActivityCommentId]
		)
	)
END
GO


PRINT '-> dbo.Notification'
IF OBJECT_ID('Notification') IS NULL
BEGIN
	CREATE TABLE dbo.[Notification]
	(
		NotificationId	[uniqueidentifier] ROWGUIDCOL NOT NULL 
			CONSTRAINT [DF_Notification_NotificationId] DEFAULT(newid()),
		NotificationDate [DATETIME] NOT NULL,
		NotificationAction INT NULL, 
		UserInfoId	 [uniqueidentifier] NOT NULL,  
		Content		 NVARCHAR(1024) NOT NULL,  
		Title            NVARCHAR(100) NOT NULL,  
		CONSTRAINT PK_Notification PRIMARY KEY CLUSTERED
		(
			[NotificationId]
		)
	)
END
GO
